package com.cetccst.securitysuite.hostsdk;

import static cn.com.cetccst.hostsdk.internal.SDKErrorCode.ERROR_OK;
import static com.cetccst.securitysuite.log.SSLogger.logger;

import android.content.Context;

import cn.com.cetccst.hostsdk.internal.ISSAPIEventLocalHandler;
import cn.com.cetccst.hostsdk.internal.SSApiImplLocal;

import cn.com.cetccst.sdk.modelbase.BaseReq;
import cn.com.cetccst.sdk.modelbase.ConstantsAPI;
import cn.com.cetccst.sdk.modelbiz.SendAuth;

public class SSApiEventHandler implements ISSAPIEventLocalHandler {

    private static final String TAG = "CXApiEventHandler";

    protected SSApiImplLocal api;

    private Context context;

    public SSApiEventHandler(Context context) {
        api = SSApiImplLocal.getInstance(context);
        this.context = context;
    }

    @Override
    public void onReq(final String appKey, final String appPackage, BaseReq baseReq) {
        logger.info("onReq [" + appKey + "][" + appPackage + "][" + baseReq + "]");
        api.holdResponseTarget(appPackage, baseReq.transaction);
        switch (baseReq.getType()) {
            case ConstantsAPI.COMMAND_SEND_AUTH: {
                //TODO 完成身份认证的业务，这里应该是单点登录的模块调用
//                OpenAppManager.getInstance().handleReq(context,  baseReq);
                //示例代码
                SendAuth.Resp resp = new SendAuth.Resp();
                resp.transaction = baseReq.transaction;
                    resp.errorCode = ERROR_OK;
                    resp.oAuthCode = "oauthcode_123456789";
                SSApiImplLocal api = SSApiImplLocal.getInstance(context);
                api.sendResp(baseReq.appKey, resp);
            }
            break;
        }
    }

}
